package top.lshaci.learning.springboot.quartz.job;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import top.lshaci.learning.springboot.quartz.service.PrintService;

/**
 * PrintJob
 *
 * @author liangxu
 */
@Slf4j
@DisallowConcurrentExecution
public class PrintJob extends QuartzJobBean {

    @Autowired
    private PrintService printService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getMergedJobDataMap();
        String color = jobDataMap.getString("color");
        String methodName = "print" + StrUtil.upperFirst(color);
        ReflectUtil.invoke(printService, methodName);
    }
}
